import { getSecond , uuid} from '../../utils/common'
import { Account , Token , AccountDetail , ProvePersonal , ProveCompany} from '../../models/'
import { CODE , TOKEN_TIME , PROGRESS_STATUS } from '../../config/config'

/**
 * @api {post} /prove/getPersonalProve 获取个人认证信息
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName getPersonalProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/getPersonalProve'
 *
 * @apiParam {String}  token                   用户token
 * 
 * @apiSuccess {Object}   personalProve     认证信息
 * @apiSuccess {String}   id                认证id
 * @apiSuccess {String}   uid               用户id
 * @apiSuccess {String}   name              姓名
 * @apiSuccess {String}   idcard            身份证
 * @apiSuccess {String}   handle_code       处理码
 * @apiSuccess {String}   img1              身份证正面
 * @apiSuccess {String}   img2              身份证背面
 * @apiSuccess {String}   status            审核状态 进度 1.申请中 2.通过认证 3.取消认证 4.认证失败 99.删除
 * @apiSuccess {String}   remark            备注
 * @apiSuccess {String}   ext               拓展信息
 * @apiSuccess {String}   ctime             创建时间
 * @apiSuccess {String}   htime             处理时间
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/getPersonalProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function getPersonalProve (ctx) {
	const token               = ctx.body.token

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

	let phone_prove_personal  = null
	let wechat_prove_personal = null
	let qq_prove_personal     = null

	if(phone_uid) {
		phone_prove_personal  = await ProvePersonal.findOne({where : {uid:phone_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(wechat_uid) {
		wechat_prove_personal = await ProvePersonal.findOne({where : {uid:wechat_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(qq_uid) {
		qq_prove_personal     = await ProvePersonal.findOne({where : {uid:qq_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	const personalProve       = phone_prove_personal || wechat_prove_personal || qq_prove_personal
	ctx.body                  = CODE.success({personalProve})
}


/**
 * @api {post} /prove/createPersonalProve 创建个人认证
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName createPersonalProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/createPersonalProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}   name              姓名
 * @apiParam {String}   idcard            身份证
 * @apiParam {String}   img1              身份证正面
 * @apiParam {String}   img2              身份证背面
 * @apiParam {String}   remark            备注
 * @apiParam {String}   ext               拓展信息
 * 
 * @apiSuccess {Object}   personalProve     认证信息
 * @apiSuccess {String}   id                认证id
 * @apiSuccess {String}    uid               用户id
 * @apiSuccess {String}   name              姓名
 * @apiSuccess {String}   idcard            身份证
 * @apiSuccess {String}   handle_code       处理码
 * @apiSuccess {String}   img1              身份证正面
 * @apiSuccess {String}   img2              身份证背面
 * @apiSuccess {String}   status            审核状态 进度 1.申请中 2.通过认证 3.取消认证 4.认证失败 99.删除
 * @apiSuccess {String}   remark            备注
 * @apiSuccess {String}   ext               拓展信息
 * @apiSuccess {String}   ctime             创建时间
 * @apiSuccess {String}   htime             处理时间
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/createPersonalProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function createPersonalProve (ctx) {
	const token               = ctx.body.token

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

	let phone_prove_personal  = null
	let wechat_prove_personal = null
	let qq_prove_personal     = null

	if(phone_uid) {
		phone_prove_personal  = await ProvePersonal.findOne({where : {uid:phone_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(wechat_uid) {
		wechat_prove_personal = await ProvePersonal.findOne({where : {uid:wechat_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(qq_uid) {
		qq_prove_personal     = await ProvePersonal.findOne({where : {uid:qq_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}

	if(phone_prove_personal || wechat_prove_personal || qq_prove_personal) {
		ctx.body = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}

	const uid                 = token.phone_uid || token.wechat_uid || token.qq_uid
	const name                = ctx.request.body.name
	const idcard              = ctx.request.body.idcard
	const img1                = ctx.request.body.img1
	const img2                = ctx.request.body.img2
	const remark              = ctx.request.body.remark
	const ext                 = ctx.request.body.ext

	const prove               = { uid , handle_code:uuid() , ctime:getSecond() , name , idcard , img1 , img2 , remark , ext}
	const personalProve       = await ProvePersonal.create(prove)
	ctx.body                  = CODE.success({personalProve})
}



/**
 * @api {post} /prove/cancelPersonalProve 取消个人认证
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName cancelPersonalProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/cancelPersonalProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}  id                      认证id
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/cancelPersonalProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function cancelPersonalProve (ctx) {
	const token               = ctx.body.token
	const id                  = ctx.request.body.id

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

    const uid                 = []

	if(phone_uid) {
		uid[uid.length]       = phone_uid
	}
	if(wechat_uid) {
		uid[uid.length]       = wechat_uid
	}
	if(qq_uid) {
		uid[uid.length]       = qq_uid
	}

	const personalProve       = await ProvePersonal.findOne({where:{uid,id}})
	if(!personalProve) {
		ctx.body              = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}
	personalProve.status      = PROGRESS_STATUS.CANCEL
	personalProve.handle_code = uuid()
	await personalProve.save()
	ctx.body                  = CODE.success()
}


/**
 * @api {post} /prove/deletePersonalProve 删除个人认证
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName deletePersonalProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/deletePersonalProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}  id                      认证id
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/deletePersonalProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function deletePersonalProve (ctx) {
	const token               = ctx.body.token
	const id                  = ctx.request.body.id

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

    const uid                 = []

	if(phone_uid) {
		uid[uid.length]       = phone_uid
	}
	if(wechat_uid) {
		uid[uid.length]       = wechat_uid
	}
	if(qq_uid) {
		uid[uid.length]       = qq_uid
	}

	const personalProve       = await ProvePersonal.findOne({where:{uid,id}})
	if(!personalProve) {
		ctx.body              = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}
	personalProve.status      = PROGRESS_STATUS.DELETE
	personalProve.handle_code = uuid()
	await personalProve.save()
	ctx.body                  = CODE.success()
}


/**
 * @api {post} /prove/perfectPersonalProve 完善个人认证
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName perfectPersonalProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/perfectPersonalProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}   name              姓名
 * @apiParam {String}   idcard            身份证
 * @apiParam {String}   img1              身份证正面
 * @apiParam {String}   img2              身份证背面
 * @apiParam {String}   remark            备注
 * @apiParam {String}   ext               拓展信息
 * 
 * @apiSuccess {Object}   personalProve     认证信息
 * @apiSuccess {String}   id                认证id
 * @apiSuccess {String}    uid               用户id
 * @apiSuccess {String}   name              姓名
 * @apiSuccess {String}   idcard            身份证
 * @apiSuccess {String}   handle_code       处理码
 * @apiSuccess {String}   img1              身份证正面
 * @apiSuccess {String}   img2              身份证背面
 * @apiSuccess {String}   status            审核状态 进度 1.申请中 2.通过认证 3.取消认证 4.认证失败 99.删除
 * @apiSuccess {String}   remark            备注
 * @apiSuccess {String}   ext               拓展信息
 * @apiSuccess {String}   ctime             创建时间
 * @apiSuccess {String}   htime             处理时间
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/perfectPersonalProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function perfectPersonalProve (ctx) {
	const token               = ctx.body.token
	const id                  = ctx.request.body.id

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

    const uid                 = []

	if(phone_uid) {
		uid[uid.length]       = phone_uid
	}
	if(wechat_uid) {
		uid[uid.length]       = wechat_uid
	}
	if(qq_uid) {
		uid[uid.length]       = qq_uid
	}

	const personalProve       = await ProvePersonal.findOne({where:{uid,id}})
	if(!personalProve) {
		ctx.body              = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}
	const name                = ctx.request.body.name
	const idcard              = ctx.request.body.idcard
	const img1                = ctx.request.body.img1
	const img2                = ctx.request.body.img2
	const remark              = ctx.request.body.remark
	const ext                 = ctx.request.body.ext

	if(personalProve.status == PROGRESS_STATUS.CANCEL || personalProve.status == PROGRESS_STATUS.FAIL) {
		personalProve.status      = PROGRESS_STATUS.APPLYING
		personalProve.name        = name || personalProve.name
		personalProve.idcard      = idcard || personalProve.idcard
		personalProve.img1        = img1 || personalProve.img1
		personalProve.img2        = img2 || personalProve.img2
		personalProve.remark      = remark || personalProve.remark
		personalProve.ext         = ext || personalProve.ext
		personalProve.status      = PROGRESS_STATUS.APPLYING
		personalProve.handle_code = uuid()
		await personalProve.save()
		ctx.body                  = CODE.success()
	}
	ctx.body                  = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
}



/**
 * @api {post} /prove/getCompanyProve 获取企业认证信息
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName getCompanyProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/getCompanyProve'
 *
 * @apiParam {String}  token                   用户token
 * 
 * @apiSuccess {Object}   personalProve     认证信息
 * @apiSuccess {String}   id                认证id
 * @apiSuccess {String}   uid               用户id
 * @apiSuccess {String}   name              企业名称
 * @apiSuccess {String}   idcard            认证类型
 * @apiSuccess {String}   code              认证号码
 * @apiSuccess {String}   img               营业执照照片
 * @apiSuccess {String}   handle_code       处理码
 * @apiSuccess {String}   status            审核状态 进度 1.申请中 2.通过认证 3.取消认证 4.认证失败 99.删除
 * @apiSuccess {String}   remark            备注
 * @apiSuccess {String}   ext               拓展信息
 * @apiSuccess {String}   ctime             创建时间
 * @apiSuccess {String}   htime             处理时间
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/getCompanyProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function getCompanyProve (ctx) {
	const token               = ctx.body.token

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

	let phone_prove_company   = null
	let wechat_prove_company  = null
	let qq_prove_company      = null

	if(phone_uid) {
		phone_prove_company   = await ProveCompany.findOne({where : {uid:phone_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(wechat_uid) {
		wechat_prove_company  = await ProveCompany.findOne({where : {uid:wechat_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(qq_uid) {
		qq_prove_company      = await ProveCompany.findOne({where : {uid:qq_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	const companyProve        = phone_prove_company || wechat_prove_company || qq_prove_company
	ctx.body                  = CODE.success({companyProve})
}


/**
 * @api {post} /prove/createCompanyProve 创建企业认证信息
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName createCompanyProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/createCompanyProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}   name              企业名称
 * @apiParam {String}   idcard            认证类型
 * @apiParam {String}   code              认证号码
 * @apiParam {String}   img               营业执照照片
 * @apiParam {String}   remark            备注
 * @apiParam {String}   ext               拓展信息
 * 
 * @apiSuccess {Object}   personalProve     认证信息
 * @apiSuccess {String}   id                认证id
 * @apiSuccess {String}   uid               用户id
 * @apiSuccess {String}   name              企业名称
 * @apiSuccess {String}   idcard            认证类型
 * @apiSuccess {String}   code              认证号码
 * @apiSuccess {String}   img               营业执照照片
 * @apiSuccess {String}   handle_code       处理码
 * @apiSuccess {String}   status            审核状态 进度 1.申请中 2.通过认证 3.取消认证 4.认证失败 99.删除
 * @apiSuccess {String}   remark            备注
 * @apiSuccess {String}   ext               拓展信息
 * @apiSuccess {String}   ctime             创建时间
 * @apiSuccess {String}   htime             处理时间
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/createCompanyProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function createCompanyProve (ctx) {
	const token               = ctx.body.token

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

	let phone_prove_company   = null
	let wechat_prove_company  = null
	let qq_prove_company      = null

	if(phone_uid) {
		phone_prove_company   = await ProveCompany.findOne({where : {uid:phone_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(wechat_uid) {
		wechat_prove_company  = await ProveCompany.findOne({where : {uid:wechat_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}
	if(qq_uid) {
		qq_prove_company      = await ProveCompany.findOne({where : {uid:qq_uid,status:{$not:PROGRESS_STATUS.DELETE}}})
	}

	if(phone_prove_company  || wechat_prove_company  || qq_prove_company ) {
		ctx.body = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}

	const uid                    = token.phone_uid || token.wechat_uid || token.qq_uid
	
	const name                   = ctx.request.body.name
	const type                   = ctx.request.body.type
	const code                   = ctx.request.body.code
	const img                    = ctx.request.body.img
	const remark                 = ctx.request.body.remark
	const ext                    = ctx.request.body.ext

	const prove                  = {remark, ext , uid , handle_code:uuid() , ctime:getSecond() , name , type , code , img }
	const proveCompany           = await ProveCompany.create(prove)
	ctx.body                     = CODE.success({proveCompany})
}



/**
 * @api {post} /prove/cancelCompanyProve 取消企业认证信息
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName cancelCompanyProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/cancelCompanyProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}  id                      企业认证id
 * 
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/cancelCompanyProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function cancelCompanyProve (ctx) {
	const token               = ctx.body.token
	const id                  = ctx.request.body.id

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

    const uid                 = []

	if(phone_uid) {
		uid[uid.length]       = phone_uid
	}
	if(wechat_uid) {
		uid[uid.length]       = wechat_uid
	}
	if(qq_uid) {
		uid[uid.length]       = qq_uid
	}

	const proveCompany       = await ProveCompany.findOne({where:{uid,id}})
	if(!proveCompany) {
		ctx.body              = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}
	proveCompany.status      = PROGRESS_STATUS.CANCEL
	proveCompany.handle_code = uuid()
	await proveCompany.save()
	ctx.body                  = CODE.success()
}


/**
 * @api {post} /prove/deleteCompanyProve 删除企业认证信息
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName deleteCompanyProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/deleteCompanyProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}  id                      企业认证id
 * 
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/deleteCompanyProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function deleteCompanyProve (ctx) {
	const token               = ctx.body.token
	const id                  = ctx.request.body.id

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

    const uid                 = []

	if(phone_uid) {
		uid[uid.length]       = phone_uid
	}
	if(wechat_uid) {
		uid[uid.length]       = wechat_uid
	}
	if(qq_uid) {
		uid[uid.length]       = qq_uid
	}

	const proveCompany       = await ProveCompany.findOne({where:{uid,id}})
	if(!proveCompany) {
		ctx.body              = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}
	proveCompany.status      = PROGRESS_STATUS.DELETE
	proveCompany.handle_code = uuid()
	await proveCompany.save()
	ctx.body                  = CODE.success()
}



/**
 * @api {post} /prove/perfectCompanyProve 完善企业认证信息
 * @apiPermission 用户
 * @apiVersion 1.0.0 
 * @apiName perfectCompanyProve
 * @apiGroup prove
 * @apiExample 请求示例:
 * curl -H "Content-Type: application/json" -X POST -d '{}' 'http://copyright.hotchain.vip/api/prove/perfectCompanyProve'
 *
 * @apiParam {String}  token                   用户token
 * @apiParam {String}   id                企业认证id
 * @apiParam {String}   name              企业名称
 * @apiParam {String}   idcard            认证类型
 * @apiParam {String}   code              认证号码
 * @apiParam {String}   img               营业执照照片
 * @apiParam {String}   remark            备注
 * @apiParam {String}   ext               拓展信息
 * 
 * @apiSuccess {Object}   personalProve     认证信息
 * @apiSuccess {String}   id                认证id
 * @apiSuccess {String}   uid               用户id
 * @apiSuccess {String}   name              企业名称
 * @apiSuccess {String}   idcard            认证类型
 * @apiSuccess {String}   code              认证号码
 * @apiSuccess {String}   img               营业执照照片
 * @apiSuccess {String}   handle_code       处理码
 * @apiSuccess {String}   status            审核状态 进度 1.申请中 2.通过认证 3.取消认证 4.认证失败 99.删除
 * @apiSuccess {String}   remark            备注
 * @apiSuccess {String}   ext               拓展信息
 * @apiSuccess {String}   ctime             创建时间
 * @apiSuccess {String}   htime             处理时间
 * @apiSampleRequest http://copyright.hotchain.vip/api/prove/perfectCompanyProve
 * @apiSuccessExample {json} 成功返回
 *     HTTP/1.1 200 OK
 *     {
    "code": 0
  }
 *
 * @apiUse ERROR
 * 
 */
export async function perfectCompanyProve (ctx) {
	const token               = ctx.body.token
	const id                  = ctx.request.body.id

	const phone_uid           = token.phone_uid
	const wechat_uid          = token.wechat_uid
	const qq_uid              = token.qq_uid

    const uid                 = []

	if(phone_uid) {
		uid[uid.length]       = phone_uid
	}
	if(wechat_uid) {
		uid[uid.length]       = wechat_uid
	}
	if(qq_uid) {
		uid[uid.length]       = qq_uid
	}

	const proveCompany        = await ProveCompany .findOne({where:{uid,id}})
	if(!proveCompany) {
		ctx.body              = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
		return
	}
	const name                   = ctx.request.body.name
	const type                   = ctx.request.body.type
	const code                   = ctx.request.body.code
	const img                    = ctx.request.body.img
	const ext                    = ctx.request.body.ext
	const remark                 = ctx.request.body.remark

	if(personalProve.status == PROGRESS_STATUS.CANCEL || personalProve.status == PROGRESS_STATUS.FAIL) {
		proveCompany.status      = PROGRESS_STATUS.APPLYING
		proveCompany.name        = name || proveCompany.name
		proveCompany.type        = idcard || proveCompany.idcard
		proveCompany.code        = code || proveCompany.code
		proveCompany.img         = img || proveCompany.img
		proveCompany.ext         = ext || proveCompany.ext
		proveCompany.remark      = remark || proveCompany.remark
		proveCompany.status      = PROGRESS_STATUS.APPLYING
		proveCompany.handle_code = uuid()
		await proveCompany.save()
		ctx.body                  = CODE.success({proveCompany})
	}
	ctx.body                  = CODE.ERROR.ERROR_PROVE_PERSONAL_ALREADY
}





export async function  checkToken(ctx,next) {
	const token 	  = ctx.request.body.token
	const tokenRes    = await Token.findOne({where : {token,status:1}})
	if(tokenRes) {
		if(tokenRes.ctime + TOKEN_TIME >= getSecond()) {
			ctx.body  = {token:tokenRes}
			if(next) {
				return next()
			}
		}
		ctx.body      = CODE.ERROR.ERROR_TOKEN_LOSE
		return
	}
	ctx.body          = CODE.ERROR.ERROR_TOKEN_NOT_CHECK
}


/**
 * @apiDefine ERROR
 * @apiErrorExample {json} 错误返回:
 *     {
 *       "code": "错误码",
 *       "error": "错误描述",
 *       "msg":"错误信息"
 *     }
 */